module.exports = class extends think.Controller {
  async __before() {
    // 根据token值获取用户id
    // think.token = this.ctx.headers['changshun-Token'] || '';
    let tempheader = this.ctx.headers;
    think.token = tempheader['changshun-token']
    // think.logger.info(hhh);
    // if (think.isObject(hhh)) {
    //   think.logger.info("i am object");
    //   think.logger.info("so i will pring--" + hhh['changshun-token']);
    // }
    const tokenSerivce = think.service('token', 'admin');
    think.userId = await tokenSerivce.getUserId();
    think.logger.info("so i--" + this.ctx.controller);
    // 只允许登录操作
    if (this.ctx.controller !== 'auth') {
      think.logger.info("so i will pring--" + think.userId);
      if (think.userId <= 0) {
        return this.fail(401, '请先登录');
      }
    }
  }
};